<template>
  <div>
    <el-dialog v-model="ViewdialogVisible" width="80%" align-center destroy-on-close draggable>
      <template #header="{ close }">
        <div class="dialog-header flex justify-between items-center">
          <div>专利审核</div>
          <el-icon class="el-icon--left cursor-pointer" @click="close">
            <CircleCloseFilled color="#fff" />
          </el-icon>
        </div>
      </template>
      <div class="pt-[30px] pb-[150px] bg-white">
        <el-tabs v-model="activeStep" class="demo-tabs">
          <el-tab-pane label="基本信息" :name="0">
            <div>
              <!-- 基本信息 -->
              <div class="bg-white mt-[10px]">
                <BaseHead>基本信息</BaseHead>
                <div class="p-[10px]">
                  <el-descriptions title="" :column="2" border label-width="140">
                    <el-descriptions-item label-class-name="gdlable" label="专利名称">{{
      ruleForm.name
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="所属单位">{{
        formatUnitId(ruleForm.unitId)
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="专利类型">{{
        formattypeId(ruleForm.typeId)
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="专利状态">{{
        formatstateId(ruleForm.stateId)
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="申请号">{{
        ruleForm.applyCode
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="申请日">{{
        ruleForm.applyDate
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="公开号"
                      v-if="ruleForm.stateId == '2' || ruleForm.stateId == '3'">{{
      ruleForm.openCode
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="公开日"
                      v-if="ruleForm.stateId == '2' || ruleForm.stateId == '3'">{{
      ruleForm.openDate
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="授权公告号" v-if="ruleForm.stateId == '3'">{{
      ruleForm.authorizeCode
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="授权公告日" v-if="ruleForm.stateId == '3'">{{
      ruleForm.authorizeDate
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="申请人">{{
        ruleForm.applyInfo
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="专利权人" v-if="ruleForm.stateId == '3'">{{
      ruleForm.patentee
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="专利权状态" v-if="ruleForm.stateId == '3'">{{
      formatinvalidFlag(ruleForm.invalidFlag)
    }}</el-descriptions-item>
                  </el-descriptions>
                </div>
              </div>
              <!-- 详细信息 -->
              <div class="bg-white mt-[10px]">
                <BaseHead>详细信息</BaseHead>
                <div class="p-[10px]">
                  <el-descriptions title="" :column="2" border label-width="140">
                    <el-descriptions-item label-class-name="gdlable" label="合作类型">{{
      formatcooperationType(ruleForm.cooperationType)
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="联合申请知识产权协议书附件"
                      v-if="ruleForm.cooperationType == '2'">
                      <div v-for="item in ruleForm.joinFileList" :key="item.id">{{
      item.fileName }}<el-link type="primary" style="margin-left: 8px;"
                          @click="downloadMet(item.id)">下载</el-link>
                      </div>
                    </el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="学校署名">{{
      ruleForm.schoolSign == 0 ? '第一单位' : '非第一单位'
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="是否职务专利">{{
        ruleForm.isDuty == 0 ? '否' : '是'
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="专利范围">{{
        formatscopeId(ruleForm.scopeId)
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="国家地区" v-if="ruleForm.scopeId == 2">
                      <Feedback :id="ruleForm.region" :list="gjdqList">
                      </Feedback>
                    </el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="是否代理">{{
      ruleForm.isAgency == 1 ? '是' : "否"
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="是否PCT专利">{{
        ruleForm.isPct == 1 ? '是' : "否"
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="IPC主分类号">{{
        ruleForm.patentIpc
      }}</el-descriptions-item>
                    <!-- <el-descriptions-item label-class-name="gdlable" label="奖励证书">奖励证书</el-descriptions-item> -->
                    <el-descriptions-item label-class-name="gdlable" label="专利证书附件">
                      <div v-for="item in ruleForm.crednetialFileList" :key="item.id">{{
      item.fileName }}<el-link type="primary" style="margin-left: 8px;"
                          @click="downloadMet(item.id)">下载</el-link>
                      </div>
                    </el-descriptions-item>
                  </el-descriptions>
                </div>
              </div>
              <!-- 代理信息 -->
              <div class="bg-white mt-[10px]" v-if="ruleForm.isAgency == '1'">
                <BaseHead>代理信息</BaseHead>
                <div class="p-[10px]">
                  <el-descriptions title="" :column="2" border label-width="140">
                    <el-descriptions-item label-class-name="gdlable" label="代理公司">{{
      ruleForm.agencyName
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="通讯发明人">{{
        ruleForm.txAuthor
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="通讯发明人电话">{{
        ruleForm.txAuthorTel
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="附件">
                      <div v-for="item in ruleForm.fileList" :key="item.id">{{ item.fileName
                        }}<el-link type="primary" style="margin-left: 8px;" @click="downloadMet(item.id)">下载</el-link>
                      </div>
                    </el-descriptions-item>
                  </el-descriptions>
                </div>
              </div>
              <!-- PCT信息 -->
              <div class="bg-white mt-[10px]" v-if="ruleForm.isPct == '1'">
                <BaseHead>PCT信息</BaseHead>
                <div class="p-[10px]">
                  <el-descriptions title="" :column="2" border label-width="140">
                    <el-descriptions-item label-class-name="gdlable" label="PCT专利名称">{{
      ruleForm.pctName
    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="PCT专利申请号">{{
        ruleForm.pctCode
      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="PCT专利申请日期">{{
        ruleForm.pctDate
                      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="PCT专利优先权日">{{
                      ruleForm.priorityDate
                      }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="进入国家">{{
                      ruleForm.enterCountry
                      }}</el-descriptions-item>
                  </el-descriptions>
                </div>
              </div>
              <!-- 发明（设计）人 -->
              <div class="bg-white mt-[10px]">
                <BaseHead>发明（设计）人 </BaseHead>
                <div class="p-[10px]">
                  <el-table :data="tableData" border style="width: 100%">
                    <el-table-column align="center" type="index" label="署名顺序" width="80" />
                    <el-table-column align="center" prop="authorType" label="发明人类型">
                      <template #default="scope">
                        {{
                        scope.row.authorType == '1' ? '教师' : scope.row.authorType == '2' ? '学生' : '校外'
                        }}</template>
                    </el-table-column>
                    <el-table-column align="center" prop="authorName" label="发明人姓名">

                    </el-table-column>
                    <el-table-column align="center" prop="eduLevelId" label="学历">
                      <template #default="scope">
                        <Feedback :id="scope.row.eduLevelId" :list="xlList">
                        </Feedback>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="学位">
                      <template #default="scope">
                        {{
                        formateduDegreeId(scope.row.eduDegreeId)
                        }}
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="authorUnit" label="工作单位">
                      <template #default="scope">
                        <span v-if="scope.row.authorType == 1">{{ scope.row.authorUnit }}</span>
                        <Feedback v-else :id="scope.row.authorUnitId" :list="sydwList"
                          :mapping="['codeColumn', 'valueColumn']">
                        </Feedback>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="titleId" label="职称">
                      <template #default="scope">
                        <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                          :render-after-expand="false" disabled />
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane label="依托项目" :name="1">
            <supportProjectView :productId="ruleForm.id"></supportProjectView>
          </el-tab-pane>
        </el-tabs>

      </div>
      <!-- <Checkcomponents :procInsId="procInsId" @success="refresh" class="mt-[10px]" /> -->
      <template #footer>
        <div class="dialog-footer">
          <Checkcomponents :procInsId="procInsId" class="mt-[10px]" @success="refresh" />
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import supportProjectView from "@/views/achievement/components/supportProjectView.vue"
import { getCategory } from "@/api/system/category"
import Checkcomponents from "@/views/flowable/processInstance/detail/components.vue";

const ViewdialogVisible = defineModel();
const props = defineProps({
  xlList: Array,
  zcList: Array,
  zcgsdwList: Array,
  xwList: Array,
  zlztList: Array,
  hzlxList: Array,
  zlfwList: Array,
  gjdqList: Array,
  sydwList: Array,
})

const ruleForm = reactive({
});
const tableData = reactive([
]);
const zllxList = ref([])

const formatUnitId = (cellValue) => {
  if (props.zcgsdwList.length && cellValue) {
    return props.zcgsdwList.find(item => item.codeColumn == cellValue).valueColumn
  } else {
    return ''
  }


}
const formattypeId = (cellValue) => {
  if (zllxList.value.length && cellValue) {
    return zllxList.value.find(item => item.code == cellValue).name
  } else {
    return ''
  }


}
const formatstateId = (cellValue) => {
  if (props.zlztList.length && cellValue) {
    return props.zlztList.find(item => item.code == cellValue).name
  } else {
    return ''
  }


}
const formatinvalidFlag = (cellValue) => {
  let invalidFlagArr = [
    {
      code: 'ineffective',
      name: '未生效'
    },
    {
      code: 'yes',
      name: '有效'
    },
    {
      code: 'rollout',
      name: '已转出'
    },
    {
      code: 'no',
      name: '无效'
    }
  ]
  return invalidFlagArr.find(item => item.code == cellValue) ? invalidFlagArr.find(item => item.code == cellValue).name : ''


}

const formatcooperationType = (cellValue) => {
  if (props.hzlxList.length && cellValue) {
    return props.hzlxList.find(item => item.code == cellValue).name
  } else {
    return ''
  }

}
const formatscopeId = (cellValue) => {
  if (props.zlfwList.length && cellValue) {
    return props.zlfwList.find(item => item.code == cellValue).name
  } else {
    return ''
  }
}

const formateduLevelId = (cellValue) => {
  if (props.xlList.length && cellValue) {
    return props.xlList.find(item => item.code == cellValue).name
  } else {
    return ''
  }


}
const formateduDegreeId = (cellValue) => {
  if (props.xwList.length && cellValue) {
    return props.xwList.find(item => item.code == cellValue).name
  } else {
    return ''
  }


}


const procInsId = ref(null); //流程实例id


const getRuleForm = (i, processId) => {
  if (i.authorList && i.authorList.length > 0) {
    tableData.length = 0; // 清空数组
    tableData.push(...i.authorList); // 添加新元素

  }
  for (const key in i) {
    ruleForm[key] = i[key];
  }
  procInsId.value = processId

}
const activeStep = ref(0)

const emit = defineEmits(['callBack']);
const refresh = () => {
  ViewdialogVisible.value = false
  emit('callBack', "")
}


let getCategoryInfoMet = async () => {
  let parms = {
    bizName: "专利类型"
  }
  let res = await getCategory(parms)
  if (res.code == 200) {
    zllxList.value = res.data
  }
}
const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
  proxy.$download.common(i)
}

defineExpose({
  getRuleForm
})
onMounted(() => {
  getCategoryInfoMet()
})
</script>
<style lang="scss">
.gdlable {
  width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


  .el-select__wrapper.is-disabled {
    background-color: #fff;
    box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
    color: #606266;
    cursor: not-allowed;

    .el-select__selected-item {
      color: #606266;
    }
  }

  .el-select__suffix {
    display: none;
  }
}
</style>
